package br.com.lambdacore.iterator;

import java.util.Iterator;
import java.util.NoSuchElementException;

public class IntegerRange implements Iterable<Integer>, Iterator<Integer> {

	private final int end;
	private int current;

	public IntegerRange(int start, int end) {
		this.current = start;
		this.end = end;
	}

	public boolean hasNext() {
		return this.current <= this.end;
	}

	public Iterator<Integer> iterator() {
		return this;
	}

	public Integer next() {
		if (!this.hasNext()) {
			throw new NoSuchElementException();
		}
		int ret = this.current;
		this.current++;
		return ret;
	}

	public void remove() {
		throw new UnsupportedOperationException("Not supported operation");
	}

	public static Iterable<Integer> range(int end) {
		return range(0, end);
	}

	public static Iterable<Integer> range(int start, int end) {
		return new IntegerRange(start, end);
	}

}
